/* =============================================================
 * System Name：Document Control System
 * File Name： RenrenAPI.java
 * --------------------------------------------------------------
 * (C) Copyright M+W Group 2012 All Rights Reserved.
 *
 *  VERSION    DATE        BY                CHANGE/COMMENT
 * ----------------------------------------------------------------
 *
 */
package com.deco.authorization.api;

import java.net.URLEncoder;

import org.scribe.builder.api.DefaultApi20;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.extractors.JsonTokenExtractor;
import org.scribe.model.OAuthConfig;
import org.scribe.model.Verb;
import org.scribe.oauth.OAuthService;

public class RenrenAPI extends DefaultApi20 {
	private static final String AUTHORIZATION_URL = "http://graph.renren.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code";

	@Override
	public String getAuthorizationUrl(OAuthConfig config) {
		return String.format(AUTHORIZATION_URL, config.getApiKey(), URLEncoder
				.encode(config.getCallback()));
	}

	@Override
	public String getAccessTokenEndpoint() {
		return "http://graph.renren.com/oauth/token?grant_type=authorization_code";
	}

	@Override
	public Verb getAccessTokenVerb() {
		return Verb.POST;
	}

	@Override
	public AccessTokenExtractor getAccessTokenExtractor() {
		return new JsonTokenExtractor();
	}

	@Override
	public OAuthService createService(OAuthConfig config) {
		return new OAuth20ServiceImpl(this, config);
	}

}
